<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Logic;


use App\Common\Logger;
use App\Exceptions\ApiException;
use App\Http\Controllers\Base;
use Illuminate\Support\Facades\DB;

class DiamondsLogic extends Logic
{

    /**
     * 处理支付成功后的操作
     * @throws \App\Exceptions\ApiException
     */
    public function handlePayCallBack($goods_id, $out_trade_no, $xml, $uid, $pay_type)
    {
        //查询商品信息
        $diamonds = DB::table('t_diamonds_mall_conf')->where('id', $goods_id)->value('diamonds');
        if (empty($diamonds)) {
            Logger::instance()->wxPayCallback("【钻石：本地数据库,查询商品信息失败】:\n$xml\n");
            PayCallBackLogic::instance()->updatePay($out_trade_no,'钻石：本地数据库,查询商品信息失败');
        }

        //给充值用户加房卡
        $ret = app(Base::class)->grant_diamonds($uid, $diamonds, $pay_type . '支付增加钻石', 'orderno：' . $out_trade_no);
        if (!$ret) {
            Logger::instance()->wxPayCallback("【本地数据库,更新玩家砖石失败】:\n$xml\n");
            PayCallBackLogic::instance()->updatePay($out_trade_no, '本地数据库,更新玩家砖石失败');
        }
    }

}